# Maintainer: kreijstal <kreijstal@hotmail.com>

_realname=xournalpp
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.2.7
pkgrel=1
pkgdesc='Handwriting notetaking software with PDF annotation support (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_repository_url='https://github.com/xournalpp/xournalpp'
url='https://xournalpp.github.io/'
license=('spdx:GPL-2.0-or-later')
depends=(
  "${MINGW_PACKAGE_PREFIX}-cairo"
  "${MINGW_PACKAGE_PREFIX}-gcc-libs"
  "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2"
  "${MINGW_PACKAGE_PREFIX}-gettext-runtime"
  "${MINGW_PACKAGE_PREFIX}-glib2"
  "${MINGW_PACKAGE_PREFIX}-gtk3"
  "${MINGW_PACKAGE_PREFIX}-gtksourceview4"
  "${MINGW_PACKAGE_PREFIX}-libsndfile"
  "${MINGW_PACKAGE_PREFIX}-libwinpthread"
  "${MINGW_PACKAGE_PREFIX}-libxml2"
  "${MINGW_PACKAGE_PREFIX}-libzip"
  "${MINGW_PACKAGE_PREFIX}-lua"
  "${MINGW_PACKAGE_PREFIX}-pango"
  "${MINGW_PACKAGE_PREFIX}-poppler"
  "${MINGW_PACKAGE_PREFIX}-portaudio"
  "${MINGW_PACKAGE_PREFIX}-zlib"
)
# rsvg and imagemagick for icon generation
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "${MINGW_PACKAGE_PREFIX}-gettext-tools"
  "${MINGW_PACKAGE_PREFIX}-imagemagick"
  "${MINGW_PACKAGE_PREFIX}-libbacktrace"
  "${MINGW_PACKAGE_PREFIX}-librsvg"
  "${MINGW_PACKAGE_PREFIX}-ninja"
  "${MINGW_PACKAGE_PREFIX}-pkgconf"
)
source=("https://github.com/xournalpp/xournalpp/archive/v${pkgver}/${_realname}-v${pkgver}.tar.gz")
sha256sums=('cd20608417fef374e5360ec96c9f56c61236d45e0d35d33b48346ed39eaf025d')

build() {
  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    "${MINGW_PREFIX}"/bin/cmake.exe \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      "${extra_config[@]}" \
      -DBUILD_SHARED_LIBS=ON \
      -S "${_realname}-${pkgver}" \
      -B "build-${MSYSTEM}"

  "${MINGW_PREFIX}"/bin/cmake.exe --build "build-${MSYSTEM}"
}

package() {
  DESTDIR="${pkgdir}" "${MINGW_PREFIX}"/bin/cmake.exe --install "build-${MSYSTEM}"

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
